﻿using System;
using System.IO;
using System.Linq;
using uPLibrary.Networking.M2Mqtt;

namespace MqttDemo
{
    class Program
    {
        static void Main(string[] args)
        {
         string mqtt_server = "gzhwedu.cn";
         int mqtt_port = 1883;
         string username = "guest";
         string password = "guest";
         string clientId = "emgrmvc-002";

        string content = File.ReadAllText("gree_off.txt");
            string[] numbers = content.Split(',');
            var q = from n in numbers select UInt16.Parse(n);
            var data = q.ToArray();
            byte[] buf = new byte[data.Length * 2]; // { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};

            for (int i = 0; i < data.Length; i++)
            {
                BitConverter.GetBytes(data[i]).CopyTo(buf, i * 2);
            }

            MqttClient client = new MqttClient(mqtt_server);
            client.Connect(clientId);
                //ConnectMQTT(mqtt_server, mqtt_port, clientId, username, password);
            client.Publish("home/202/ir/1", buf);

        }
    }
}
